@extends('layout')
@section('content')
    <nav class="breadcrumb">
        <i class="Hui-iconfont">&#xe67f;</i>
        当前位置: <span class="c-gray en">&gt;</span>
        游戏管理 <span class="c-gray en">&gt;</span>
    <a style="color:blue;" href="{{ url('nonPublicVersion/game') }}" >游戏列表</a> <span class="c-gray en">&gt;</span>
        生成渠道包
    </nav>
    <article class="page-container" id="app">
        <form action="{{ url('nonPublicVersion/gamePackage') }}" method="post" class="form form-horizontal" id="form-member-add">
            {{ csrf_field() }}
            <div class="row cl">
                <div class="col-sm-8 col-offset-1" style="margin-left: 4.33333%">
                    游戏名称: {{ $game_name }} &nbsp;&nbsp;&nbsp; 开发商: {{ $supplier_name }} &nbsp;&nbsp;&nbsp; 手机系统:{{ $platform }}
                </div>
            </div>

            <input type="hidden" value="{{$game_id}}" name="game_id">

            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>渠道名称：</label>
                <div class="formControls col-xs-8 col-sm-9">



                    <span class="col-xs-8" style="position: relative;">
                        <el-select v-model="value8" v-on:change="change" filterable placeholder="请选择" style="width: 100%">
                        <el-option
                                v-for="item in options"
                                :label="item.label"
                                :value="item.value">
                        </el-option>
                    </el-select>
                    <input type="hidden" name="channel_id" id="channel_id" value="" v-model="value8">
                       {{-- <select class="select" size="1" name="channel_id" id="channel_id">
                            <option value="" selected>--请选择--</option>
                            @foreach($channels as $item)
                                <option value="{{ $item->id }}">{{ $item->name }}</option>
                            @endforeach
                        </select>--}}
				    </span>
                    <div>
                    </div>
                </div>
            </div>

            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2">所属父渠道：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <span id="father"></span>
                </div>
            </div>

            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2">一级渠道：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <span id="one"></span>
                </div>
            </div>

            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2">二级渠道：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <span id="two"></span>
                </div>
            </div>

            {{--<div class="row cl">--}}
                {{--<label class="form-label col-xs-4 col-sm-2">打包方式：</label>--}}
                {{--<div class="formControls col-xs-8 col-sm-9">--}}
                    {{--<input type="radio" name="type" checked> apk--}}
                    {{--<input type="radio" name="type" > zip--}}
                {{--</div>--}}
            {{--</div>--}}

            <div class="row cl">
                <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
                    <input class="btn btn-primary radius" type="submit" value="生成">
                </div>
            </div>
        </form>

    </article>
@endsection
@section('script')
    <script type="application/javascript">

        new Vue({
            el: '#app',
            data: function(){
                return {
                    options: '',
                    value8: ''
                }
            },
            methods: {
                loadAll : function ()  {
                    this.getGames('');
                },
                getGames:function (keywords) {
                    var self = this;
                    keywords = keywords ? keywords : '';
                    request('{{ url('/nonPublicVersion/getChannel') }}',function (data) {
                        self.options= data;
                    });
                },
                change:function (id) {
                    request('{{ url('nonPublicVersion/getChannel') }}' + '/' + id,function (data) {
                        $("#father").html(data.father);
                        $("#one").html(data.one);
                        $("#two").html(data.two);
                    },'','get');
                }
            },
            mounted:function() {
                this.loadAll();
            }
        });

        $(function () {

            $("#form-member-add").validate({
                rules:{
                    name:{
                        required:true,
                        minlength:1,
                        maxlength:50
                    },
                    key:{
                        required:true,
                    },
                    callback_url:{
                        required:true,
                    },
                },
                onkeyup:false,
                focusCleanup:true,
                success:"valid",
                submitHandler:function(form){
                    var url = $(form).attr('action');
                    $(form).ajaxSubmit(function (data) {
                        if(data.code == '1007'){
                            var index = layer.confirm(data.msg, {
                                btn: ['确认','取消'], //按钮
                                title:'提示'
                            }, function(){
                                request(url,function (data) {
                                    layer.confirm('打包任务已经提交，请十分钟后下载渠道包',{
                                        btn: ['确认'], //按钮
                                        title:'提示'
                                    },function () {
                                        var index = parent.layer.getFrameIndex(window.name);
                                        parent.$('#btn-refresh').click();
                                        parent.layer.close(index);
                                    })
                                },data.data,'POST');
                            });
                            return;
                        }

                        if (data.code != 0){
                            layer.confirm(data.msg, {
                                btn: ['确定','取消'] //按钮
                            });
                            return ;
                        }

                        layer.confirm('打包任务已经提交，请十分钟后下载渠道包',{
                            btn: ['确认'], //按钮
                            title:'提示'
                        },function () {
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.$('#btn-refresh').click();
                            parent.layer.close(index);
                        });
                    });
                }
            });
        })
    </script>
@endsection